// i.d(t, { O: () => Floor })

import * as THREE from "three"
class OrderList {
  list: any[]
  constructor() {
    this.list = []
  }
  insort(e) {
    const t = this.binarySearch(e)
    let i = t.index
    if (!t.success) for (; this.compare(e, this.list[i]) >= 0 && i < this.list.length; ) i++
    for (let e = this.list.length; e > i; e--) this.list[e] = this.list[e - 1]
    this.list[i] = e
  }
  removeIndex(e) {
    if (e > this.list.length) throw Error("OrderList.removeIndex() -> Invalid index: " + e)
    this.list.splice(e, 1)
  }
  getElement(e) {
    if (e >= 0 && e < this.list.length) return this.list[e]
    throw new Error("OrderList.getElement() -> Invalid index: " + e)
  }
  get length() {
    return this.list.length
  }
  find(e) {
    const t = this.binarySearch(e)
    return t.success ? t.index : -1
  }
  compare(e, t) {
    return void 0 === t ? 1 : "number" == typeof e ? (e === t ? 0 : e < t ? -1 : 1) : e.compare(t)
  }
  binarySearch(e) {
    let t = 0,
      i = this.list.length - 1,
      n = -1,
      s = null,
      r = 0
    for (; t <= i; ) {
      if (((n = Math.floor((t + i) / 2)), (s = this.list[n]), (r = this.compare(e, s)), 0 === r)) return { success: !0, index: n }
      r < 0 ? (i = n - 1) : (t = n + 1)
    }
    return { success: !1, index: n }
  }
}
import funcUtil from "../utils/func.util"
import ObservableObject from "../observer/observable.object"

export default class Floor extends ObservableObject {
  name: string
  center: THREE.Vector3
  boundingBox: THREE.Box3
  size: THREE.Vector3
  runtimeOnly: boolean
  sweepHeights: OrderList
  sweepFloorHeights: OrderList
  id: string
  meshGroup: number
  index: number
  constructor(e = {}) {
    super(),
      (this.name = ""),
      (this.center = new THREE.Vector3()),
      (this.boundingBox = new THREE.Box3()),
      (this.size = new THREE.Vector3()),
      (this.runtimeOnly = !1),
      (this.sweepHeights = new OrderList()),
      (this.sweepFloorHeights = new OrderList()),
      Object.assign(this, e)
  }
  minSweepFloorHeight() {
    return this.sweepFloorHeights.length > 0 ? this.sweepFloorHeights.getElement(0) : this.boundingBox.min.y
  }
  medianSweepHeight() {
    return this.sweepHeights.length > 0 ? this.sweepHeights.getElement(Math.floor(this.sweepHeights.length / 2)) : this.center.y
  }
  setBounds(e: THREE.Box3) {
    this.boundingBox.copy(e)
    this.boundingBox.getSize(this.size)
    this.boundingBox.getCenter(this.center)
  }
  addSweep(e) {
    this.sweepHeights.insort(e.position.y), this.sweepFloorHeights.insort(e.floorPosition.y)
  }
  get bottom() {
    return this.minSweepFloorHeight()
  }
  get top() {
    return this.sweepFloorHeights.length > 0 ? this.sweepFloorHeights.getElement(this.sweepFloorHeights.length - 1) : this.boundingBox.max.y
  }
  deepCopy() {
    return funcUtil.deepCopy({
      id: this.id,
      meshGroup: this.meshGroup,
      index: this.index,
      name: this.name,
      center: this.center,
      boundingBox: this.boundingBox,
      size: this.size,
      medianSweepHeight: this.medianSweepHeight(),
      bottom: this.bottom
    })
  }
}
